package engine.classes
{
	import engine.utils.Key;
	
	import org.osflash.signals.Signal;

	public class ToggleKey
	{
		public var key:uint;
		public var pressed:Signal = new Signal();
		
		private var _active:Boolean = false;
		
		public function ToggleKey(key:uint)
		{
			this.key = key;
		}
		
		public function destroy():void
		{
			this.pressed.removeAll();
			this.pressed = null;
		}
		
		public function update(...args):void
		{
			if(Key.isDown(this.key))
			{
				if(!this._active)
				{
					this._active = true;
					this.pressed.dispatch.apply(null, args);
				}
			}
			else this._active = false;
		}
	}
}